using System.Collections.Generic;
using Provausio.Common.Objects;
using TrainingManagement.api.Models.Data.CRUD;
using TrainingManagement.api.Models.Data.CRUD.SkillSet;

namespace TrainingManagement.api.Models.BusinessLogic.SkillSet
{
    public class SkillSetSelectOperation : BusinessOperation<int?, List<BusinessObjects.SkillSet>>
    {
        readonly SkillSetSelectDataSource _skillSetDataSource = new SkillSetSelectDataSource();
        readonly SkillSetItemsSelectDataSource _skillSetItemsSelectDataSource = new SkillSetItemsSelectDataSource();

        public override List<BusinessObjects.SkillSet> Run(int? input)
        {
            return _skillSetDataSource.Execute(input);
        }

        public List<BusinessObjects.SkillSet> Run(int? input, bool loadSkills)
        {
            var results = Run(input);
            if (loadSkills)
            {
                foreach (var skillset in results)
                {
                    skillset.SkillSetItems = _skillSetItemsSelectDataSource.Execute(skillset.SkillSetId);
                }
            }
            return results;
        }
    }
}